#pragma once
#include <Fusion.h>
#include <string>

#include "../../wxx_error.hpp"

namespace wxx {
namespace clr {
namespace fusion {

	struct assembly_name
	{
		assembly_name(const std::wstring& name)
			: m_Name(0)
		{
			ensure_success_hr(
				::CreateAssemblyNameObject(&m_Name, name.c_str(), 0, 0)
			);
		}

		assembly_name(const assembly_name& other)
			: m_Name(0)
		{
		}

		assembly_name& operator=(const assembly_name& other)
		{
			if(m_Name)
			{
				m_Name->Release();
			}
		}

		~assembly_name()
		{
			if (m_Name)
			{
				m_Name->Release();
			}
		}

	private:

		void assign(const assembly_name& other)
		{
			IAssemblyName* old = m_Name;
			IAssemblyName* clone = 0;

			ensure_success_hr(
				other.m_Name->Clone(&clone)
			);

			if (clone)
			{
				m_Name = clone;
			}

			if (old) 
			{
				old->Release();
			}
			
		}

		LPASSEMBLYNAME m_Name;
	};

}}}